class Solution {
public:
    string reverseOnlyLetters(string s) {
        size_t left = 0;
        size_t right = s.size() - 1;
        while(left < right){
            while(left < right && !isalpha(s[left]))
                left++;
            while(left < right && !isalpha(s[right]))
                right--;
            if(left < right){
                swap(s[left], s[right]);
                left++;
                right--;
            }
        }
        return s;
    }
};